﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace MyWeb.Data
{
    public class SqlDataProvider
    {
        // Lay ve chuoi ket noi toi Database
        public static string connectionString =
            System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

        public static SqlConnection connection;
        public SqlDataProvider()
        {
            // Kiem tra xem da co chuoi ket noi chua. Chua co thi tao moi
            if (connection == null)
            {
                connection = new SqlConnection(connectionString);
            }
        }

        public SqlConnection GetConnection()
        {
            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
                return connection;
            }
            else
            {

                return connection;
            }
        }
    }
}
